//
// Created by xili on 2024/8/6 8:35.
// Go big or go home.
//
#include <iostream>

using namespace std;

class Solution {
public:
    int countBinarySubstrings(string s) {
        int ans = 0, per = 0, n = s.size(), last = 0;
        while (per < n) {
            char c = s[per];
            int count = 0;
            while (per < n && s[per] == c) {
                per++;
                count++;
            }
            ans += min(last, count);
            last = count;
        }
        return ans;
    }
};